package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.PdfFile;
import com.ruoyi.system.service.IPdfFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 成绩pdf管理Controller
 *
 * @author hdj
 * @date 2025-09-09
 */
@RestController
@RequestMapping("/system/file")
public class PdfFileController extends BaseController {
    @Autowired
    private IPdfFileService pdfFileService;

/**
 * 查询成绩pdf管理列表
 */
@PreAuthorize("@ss.hasPermi('system:file:list')")
@GetMapping("/list")
    public TableDataInfo list(PdfFile pdfFile) {
        startPage();
        List<PdfFile> list = pdfFileService.selectPdfFileList(pdfFile);
        return getDataTable(list);
    }

    /**
     * 导出成绩pdf管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "成绩pdf管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PdfFile pdfFile) {
        List<PdfFile> list = pdfFileService.selectPdfFileList(pdfFile);
        ExcelUtil<PdfFile> util = new ExcelUtil<PdfFile>(PdfFile. class);
        util.exportExcel(response, list, "成绩pdf管理数据");
    }

    /**
     * 获取成绩pdf管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(pdfFileService.selectPdfFileById(id));
    }

    /**
     * 新增成绩pdf管理
     */
    @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "成绩pdf管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PdfFile pdfFile) {
        return toAjax(pdfFileService.insertPdfFile(pdfFile));
    }

    /**
     * 修改成绩pdf管理
     */
    @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "成绩pdf管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PdfFile pdfFile) {
        return toAjax(pdfFileService.updatePdfFile(pdfFile));
    }

    /**
     * 删除成绩pdf管理
     */
    @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "成绩pdf管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pdfFileService.deletePdfFileByIds(ids));
    }
}
